package comOne.servlet.impl;

import com.util.JdbcUtils;
import comOne.domain.Studnets;
import comOne.service.impl.loginServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

@WebServlet("/servlet")
public class StuservletImpl extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf-8");
        try {
            String username = req.getParameter("username");
            String password = req.getParameter("password");
            Studnets studnets = new Studnets(username, password);
            loginServiceImpl loginService = new loginServiceImpl();
            int i = loginService.loginServicestu(studnets);
            if (i==1){
            resp.getWriter().write("登陆成功");
            return;
            }else {
                resp.getWriter().write("登陆失败，3秒后返回");
                resp.setHeader("Refresh", "3;URL=/log.jsp");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
